package org.gpp.proj1.logic.core.board;

import java.util.LinkedList;
import java.util.List;

import org.gpp.proj1.map.GameMap;

public class BoardPositionGenerator {

	public static List<RobotPosition> generatePositions( int numRobots, GameMap gameMap ) {
		
		int rows = gameMap.getMapWidth();
		int cols = gameMap.getMapLength();
		
		boolean[][] occupied = new boolean[rows][cols];
		for( int c = 0; c < cols; c++ ) {
			for( int r = 0; r < rows; r++ ) {
				occupied[r][c] = false;
			}
		}
		
		List<RobotPosition> assignments = new LinkedList<RobotPosition>();
		
		int assigned = 0;
		while( assigned < numRobots ) {
			
			int x = (int)(Math.random() * (cols - 1));
			int y = (int)(Math.random() * (rows - 1));
			
			if( ! occupied[y][x] && gameMap.getModifiers()[y][x] != GameMap.UNREACHABLE ) {

				assignments.add( new RobotPosition( FacingSides.random(), x, y ) );
				occupied[y][x] = true;
				assigned++;
			}
		}
		
		return assignments;
	}

	public static void main(String[] args) {
		
	}
}
